package com.ruoyi.washer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.washer.domain.XwAgent;
import com.ruoyi.washer.service.IXwAgentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代理商Controller
 * 
 * @author hawking
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/washer/agent")
public class XwAgentController extends BaseController
{
    @Autowired
    private IXwAgentService xwAgentService;

    /**
     * 查询代理商列表
     */
    @PreAuthorize("@ss.hasPermi('washer:agent:list')")
    @GetMapping("/list")
    public TableDataInfo list(XwAgent xwAgent)
    {
        startPage();
        List<XwAgent> list = xwAgentService.selectXwAgentList(xwAgent);
        return getDataTable(list);
    }

    /**
     * 导出代理商列表
     */
    @PreAuthorize("@ss.hasPermi('washer:agent:export')")
    @Log(title = "代理商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XwAgent xwAgent)
    {
        List<XwAgent> list = xwAgentService.selectXwAgentList(xwAgent);
        ExcelUtil<XwAgent> util = new ExcelUtil<XwAgent>(XwAgent.class);
        util.exportExcel(response, list, "代理商数据");
    }

    /**
     * 获取代理商详细信息
     */
    @PreAuthorize("@ss.hasPermi('washer:agent:query')")
    @GetMapping(value = "/{agentId}")
    public AjaxResult getInfo(@PathVariable("agentId") Long agentId)
    {
        return success(xwAgentService.selectXwAgentByAgentId(agentId));
    }

    /**
     * 新增代理商
     */
    @PreAuthorize("@ss.hasPermi('washer:agent:add')")
    @Log(title = "代理商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XwAgent xwAgent)
    {
        return toAjax(xwAgentService.insertXwAgent(xwAgent));
    }

    /**
     * 修改代理商
     */
    @PreAuthorize("@ss.hasPermi('washer:agent:edit')")
    @Log(title = "代理商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XwAgent xwAgent)
    {
        return toAjax(xwAgentService.updateXwAgent(xwAgent));
    }

    /**
     * 删除代理商
     */
    @PreAuthorize("@ss.hasPermi('washer:agent:remove')")
    @Log(title = "代理商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agentIds}")
    public AjaxResult remove(@PathVariable Long[] agentIds)
    {
        return toAjax(xwAgentService.deleteXwAgentByAgentIds(agentIds));
    }
}
